package com.dd.ms.provider.web.converter;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dd.ms.provider.pojo.params.DataObjectQueryParams;
import com.dd.ms.provider.web.pojo.DO.DataObjectDO;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/6/22 17:07
 * @Description 数据对象查询条件构造器
 */
public class DataObjectQryBuilder {

    public static LambdaQueryWrapper<DataObjectDO> buildLQW(DataObjectQueryParams params) {
        LambdaQueryWrapper<DataObjectDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        if (params != null) {
            if (params.getIntValueMin() != null) {
                lambdaQueryWrapper.ge(DataObjectDO::getIntValue, params.getIntValueMin());
            }
            if (params.getIntValueMax() != null) {
                lambdaQueryWrapper.le(DataObjectDO::getIntValue, params.getIntValueMax());
            }
            if (params.getLongValueMin() != null) {
                lambdaQueryWrapper.ge(DataObjectDO::getLongValue, params.getLongValueMin());
            }
            if (params.getLongValueMax() != null) {
                lambdaQueryWrapper.le(DataObjectDO::getLongValue, params.getLongValueMax());
            }
            if (params.getDoubleValueMin() != null) {
                lambdaQueryWrapper.ge(DataObjectDO::getDoubleValue, params.getDoubleValueMin());
            }
            if (params.getDoubleValueMax() != null) {
                lambdaQueryWrapper.le(DataObjectDO::getDoubleValue, params.getDoubleValueMax());
            }
            if (params.getStringValue() != null) {
                lambdaQueryWrapper.like(DataObjectDO::getStringValue, params.getStringValue());
            }
            if (params.getJsonValue() != null) {
                lambdaQueryWrapper.like(DataObjectDO::getJsonValue, params.getJsonValue());
            }
            if (params.getLocalDateTimeValueStart() != null) {
                lambdaQueryWrapper.ge(DataObjectDO::getLocalDateTimeValue, params.getLocalDateTimeValueStart());
            }
            if (params.getLocalDateTimeValueEnd() != null) {
                lambdaQueryWrapper.le(DataObjectDO::getLocalDateTimeValue, params.getLocalDateTimeValueEnd());
            }
        }
        return lambdaQueryWrapper.orderByDesc(DataObjectDO::getUpdatedAt);
    }
}
